home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Demos / Extend 3.0 Demo / Demo Libraries / Demo Plotter Lib / Demo Plotter Lib.rsrc / MODL_5098_Plotter, I_O < prev    next >
Encoding:
Text File  |  1994-07-26  |  8.4 KB  |  318 lines

  1. real    p0[], p1[], p2[], p3[];
  2. real     timeArray[];            ** for discrete event Exec testing
  3. integer    con0, con1, con2, con3, out0, out1, out2, out3;
  4. integer nSteps, cStep, saveNSteps, incoming;
  5.  
  6. **     This is just the plotter from the Electronics library with a new face
  7. **    Copyright © 1989-1994 by Imagine That, Inc.
  8. **    All Rights Reserved.
  9. **    Extend Plotter Library, Plotter, I/O; Bob Diamond
  10. **        modified     12/13/91 JSL modified for V2.0
  11. **                    2/23/93  JSL added incoming for Output only plotters
  12. **                    10/8/93  JSL changed in0-3 to con0-3 + added report data
  13. **                    2/1/94   DJK added show plot at end of simulation
  14. **                    2/23/94  DJK modified error check for n (number of observations between plot points) to < 100000
  15. **                    4/1/94     DJK modified report and trace
  16. **                    6/2/94     DJK added openModel message handler
  17.  
  18. on checkData
  19. {
  20.     sysGlobal1 = 0.0;    ** prevent false reports
  21.     sysGlobal2 = 0.0;    ** prevent false debugs
  22.     
  23.     ** Find out if inputs are connected to determine
  24.     ** which are being used as input or output
  25.     ** and save their states for plotting decisions
  26.     ** in simulate message
  27.     con0 = con0in;    ** save values for later decisions
  28.     con1 = con1in;    ** as integer (faster)
  29.     con2 = con2in;    ** They are TRUE if inputs
  30.     con3 = con3in;    ** connected to a signal
  31.  
  32.     incoming = con3 + con2 + con1 + con0;
  33.  
  34.     out0 = con0out;    ** save values for later decisions
  35.     out1 = con1out;    ** as integer (faster)
  36.     out2 = con2out;    ** They are TRUE if inputs
  37.     out3 = con3out;    ** connected to a signal
  38.     
  39.     if (incoming && !out0)
  40.         {
  41.         makeArray(p0, 0);    ** compress arrays
  42.         installArray(0, 0, "", p0, startTime, endTime, 
  43.                         0, 0, blackPattern, cyanColor);
  44.         }
  45.     if (incoming && !out1)
  46.         {
  47.         makeArray(p1, 0);
  48.         installArray(0, 1, "", p1, startTime, endTime, 
  49.                         0, 0, dkgrayPattern, redColor);
  50.         }
  51.     if (incoming && !out2)
  52.         {
  53.         makeArray(p2, 0);
  54.         installArray(0, 2, "", p2, startTime, endTime, 
  55.                         0, 0, grayPattern, greenColor);
  56.         }
  57.     if (incoming && !out3)
  58.         {
  59.         makeArray(p3, 0);
  60.         installArray(0, 3, "", p3, startTime, endTime, 
  61.                         0, 0, ltgrayPattern, blackColor);
  62.         }
  63.  
  64.     if (nth && (noValue(n) || n < 2 || n > 100000))
  65.         {
  66.         userError("N must be between 2 and 100000 in Plotter I/O block.");
  67.         abort;
  68.         }
  69. }
  70.  
  71. on initsim
  72. {
  73.     **    First check to make sure Discrete Event Exec is not being used
  74.     if( getPassedArray(sysGlobal0, timeArray) )
  75.         {
  76.         userError("The Plotter I/O does not work with the Discrete Event Exec in block number "+(MyBlockNumber()));
  77.         abort;
  78.         }
  79.  
  80.     ** if no inputs are connected, don't do anything
  81.     ** so that the user can use the saved data for input
  82.     if (not (con0 || con1 || con2 || con3))
  83.         return;
  84.     
  85.     ** set up the local numsteps if using nth point
  86.     if (nth)
  87.         nSteps = numSteps / n + 1;
  88.     else
  89.         nSteps = numSteps;
  90.  
  91.     ** check each input connector.  If it is connected
  92.     ** the user is using that signal to plot simulation
  93.     ** results, so resize the array using makeArray.
  94.     
  95.     ** If it isn't connected, compress the signal array
  96.     
  97.     if (con0)    ** is input connector TRUE (connected)
  98.         makeArray(p0, nsteps);    ** yes, input.  Resize array
  99.     else
  100.         makeArray(p0, 0);    ** no, compress array
  101.     if (con1)    ** is input connector TRUE (connected)
  102.         makeArray(p1, nsteps);    ** yes, input.  Resize array
  103.     else
  104.         makeArray(p1, 0);    ** no, compress array            
  105.     if (con2)    ** is input connector TRUE (connected)
  106.         makeArray(p2, nsteps);    ** yes, input.  Resize array
  107.     else
  108.         makeArray(p2, 0);    ** no, compress array    
  109.     if (con3)    ** is input connector TRUE (connected)
  110.         makeArray(p3, nsteps);    ** yes, input.  Resize array
  111.     else
  112.         makeArray(p3, 0);    ** no, compress array
  113.         
  114.     installArray(0, 0, "", p0, startTime, endTime, 
  115.                     0, 0, blackPattern, cyanColor);
  116.     installArray(0, 1, "", p1, startTime, endTime, 
  117.                     0, 0, dkgrayPattern, redColor);
  118.     installArray(0, 2, "", p2, startTime, endTime, 
  119.                     0, 0, grayPattern, greenColor);
  120.     installArray(0, 3, "", p3, startTime, endTime, 
  121.                     0, 0, ltgrayPattern, blackColor);
  122.     
  123.     if (nth)
  124.         {
  125.         saveNSteps    = numSteps;
  126.         numSteps    = nSteps;
  127.         }
  128.  
  129.     retimeAxis(0);
  130.     if (nth)
  131.         numSteps = saveNSteps;
  132.     
  133.     if( showDuring )
  134.         showPlot(0, "Plotter I/O");
  135. }
  136.  
  137.  
  138. on simulate
  139. {
  140.     ** check each saved input connector state
  141.     
  142.     ** if it is TRUE, the input connector was
  143.     ** connected, so plot the new point and also
  144.     ** pass the value to the output in case it is
  145.     ** also connected.
  146.     
  147.     ** if it is FALSE, the input connector wasn't
  148.     ** connected, so get the output value from
  149.     ** the previously stored signal in the plot
  150.     ** and put it in the output connector
  151.  
  152.     if (nth && (currentStep mod n != 1))
  153.         return;
  154.  
  155.     if (nth)
  156.         {
  157.         cStep = currentStep / n;
  158.         }
  159.     else
  160.         cStep = currentStep;
  161.  
  162.     if (con0)    ** this value was saved in initsim message
  163.         {
  164.         plotNewPoint(0,0,cStep,con0in);
  165.         con0Out = con0In;    ** pass to output also
  166.         }
  167.     else                    ** get output from stored signal
  168.         con0out = GetSignalValue(0, 0, currentTime);
  169.         
  170.     if (con1)
  171.         {
  172.         plotNewPoint(0,1,cStep,con1in);
  173.         con1Out = con1In;    ** pass to output also
  174.         }
  175.     else    ** get output from stored signal
  176.         con1Out = GetSignalValue(0, 1, currentTime);
  177.     
  178.     if (con2)
  179.         {
  180.         plotNewPoint(0,2,cStep,con2in);
  181.         con2Out = con2In;    ** pass to output also
  182.         }
  183.     else    ** get output from stored signal
  184.         con2Out = GetSignalValue(0, 2, currentTime);
  185.     
  186.     if (con3)
  187.         {
  188.         plotNewPoint(0,3,cStep,con3in);
  189.         con3Out = con3In;    ** pass to output also
  190.         }
  191.     else    ** get output from stored signal
  192.         con3Out = GetSignalValue(0, 3, currentTime);
  193.         
  194.     ** sysGlobal2 is the file reference number for the DEBUG TRACE
  195.     if( sysGlobal2 != 0.0 ) ** 0 is error for open file for TRACE
  196.         {
  197. // template for trace:       |BLOCK NAME *****************|block number |BLOCK NUMBER*******|.| Current Time:|CURRENTTIME  |.|
  198.         fileWrite(sysGlobal2,"Plotter,I/O                  block number "+(myBlockNumber())+".  Current Time:"+currentTime+".","",True);
  199.         if(getBlockLabel(myBlockNumber()) != "")
  200.             fileWrite(sysGlobal2,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
  201.         fileWrite(sysGlobal2,"     Input 1 = "+con0In,"",True);
  202.         fileWrite(sysGlobal2,"     Input 2 = "+con1In,"",True);
  203.         fileWrite(sysGlobal2,"     Input 3 = "+con2In,"",True);
  204.         fileWrite(sysGlobal2,"     Input 4 = "+con3In,"",True);
  205.         fileWrite(sysGlobal2," ","",True);
  206.         }
  207. }
  208.  
  209.  
  210. on endsim
  211. {
  212.     integer loop, i;
  213.     string    str;
  214.  
  215.     if( showEnd )
  216.         showPlot(0, "Plotter I/O");
  217.  
  218.     if (con0 || con1 || con2 || con3)
  219.         pushPlotPic(0);
  220.  
  221.     ** sysGlobal1 is the file reference number for the TEXT REPORT
  222.     if( sysGlobal1 != 0.0 ) ** 0 is error, check for open file for REPORT
  223.         {
  224. // template for report:      |BLOCK NAME *****************|block number |BLOCK NUMBER*******
  225.         fileWrite(sysGlobal1,"Plotter, I/O                 block number "+(myBlockNumber()),"",True);
  226.         if(getBlockLabel(myBlockNumber()) != "")
  227.             fileWrite(sysGlobal1,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
  228.         if( comments != "" )
  229.             fileWrite(sysGlobal1,"     "+comments,"",True);
  230.         fileWrite(sysGlobal1,"  Input Parameters:","",True);
  231.         if( showDuring )
  232.             fileWrite(sysGlobal1,"     Plot is shown during simulation","",True);
  233.         else
  234.             fileWrite(sysGlobal1,"     Plot is hidden during simulation","",True);
  235.  
  236.         i = 0;
  237.         loop = TRUE;
  238.         while(loop)
  239.             {
  240.             str = "";
  241.             if (con0)
  242.                 str = p0[i];
  243.             str += "    ";
  244.             if (con1)
  245.                 str += p1[i];
  246.             str += "    ";
  247.             if (con2)
  248.                 str += p2[i];
  249.             str += "    ";
  250.             if (con3)
  251.                 str += p3[i];
  252.             fileWrite(sysGlobal1, str, "", true);
  253.             i++;
  254.             if (i >= numSteps-1)
  255.                 {
  256.                 loop = FALSE;
  257.                 break;
  258.                 }
  259.             if ((!con0 || novalue(p0[i])) &&
  260.                 (!con1 || novalue(p1[i])) &&
  261.                 (!con2 || novalue(p2[i])) &&
  262.                 (!con3 || novalue(p3[i])))
  263.                 loop = FALSE;
  264.             }
  265.  
  266.         fileWrite(sysGlobal1," ","",True);
  267.         }
  268. }
  269.  
  270.  
  271. on dialogOpen
  272. {
  273.     showplot(0, "Plotter Input/Output");
  274.     abort;    ** stop the dialog from opening!
  275. }
  276.  
  277.  
  278. on showP
  279. {
  280.     showplot(0, "Plotter Input/Output");
  281. }
  282.  
  283.  
  284. on createBlock
  285. {
  286.     ** install a dummy axis
  287.     installAxis(0, "Plotter I/O", "Time", FALSE, 0.0, 1.0,
  288.             "Value", 0, -1.0, 1.0, "Y2", 0, -1.0, 1.0, 
  289.             blackpattern, blackcolor, 100);
  290.     
  291.     ** now, install 4 dummy array signals
  292.     ** to store plotting values from a simulation
  293.     ** or from Pasteing (Importing) tabular data
  294.     
  295.     makeArray(p0, 0);
  296.     installArray(0, 0, "", p0, 0.0, 1.0, 
  297.                     0, 0, blackPattern, cyanColor);
  298.     makeArray(p1, 0);
  299.     installArray(0, 1, "", p1, 0.0, 1.0,
  300.                     0, 0, dkgrayPattern, redColor);
  301.     makeArray(p2, 0);
  302.     installArray(0, 2, "", p2,0.0, 1.0, 
  303.                     0, 0, grayPattern, greenColor);
  304.     makeArray(p3, 0);
  305.     installArray(0, 3, "", p3, 0.0, 1.0,
  306.                     0, 0, ltgrayPattern, blackColor);
  307.                     
  308.     showDuring = 1;        ** default show plot during simulation
  309.     nth    = FALSE;
  310.     n    = 10;
  311. }
  312.  
  313.  
  314. on openModel
  315. {
  316.     if(!showDuring && !showEnd && !noPlot)
  317.         noPlot = 1;
  318. }